package com.gexiaobao.pigeon.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.ProvinceEntity
import me.yokeyword.indexablerv.IndexableAdapter


/**
 * @Author      : hxw
 * @Date        : 2024/4/16 15:24
 * @Describe    :
 */


class AreaAddressAdapter(private val mContext: Context) : IndexableAdapter<ProvinceEntity>() {

    override fun onCreateTitleViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        // 创建 TitleItem 布局
        val view = LayoutInflater.from(mContext).inflate(R.layout.mine_head_item, parent,false)
        return IndexVH(view)
    }

    override fun onCreateContentViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        // 创建 内容Item 布局
        val view: View = LayoutInflater.from(mContext).inflate(R.layout.item_contact, parent,false)
        return ContentVH(view)
    }

    override fun onBindTitleViewHolder(holder: RecyclerView.ViewHolder, indexTitle: String) {
        // 填充 TitleItem 布局
        val holderTemp = holder as IndexVH
        holderTemp.tv.text = indexTitle
    }

    override fun onBindContentViewHolder(holder: RecyclerView.ViewHolder, entity: ProvinceEntity) {
        // 填充 内容Item 布局
        val holderTemp = holder as ContentVH
        holderTemp.title.text = entity.name
    }

    //获取数据布局组件
    class ContentVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var title: TextView

        init {
            title = itemView.findViewById(R.id.tv_name)
        }
    }

    //获取提示栏布局组件
    private class IndexVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var tv: TextView

        init {
            tv = itemView.findViewById(R.id.tv_index) as TextView
        }
    }
}
